/*
 * FileName：PaperIndexCtrl.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.wx.wxcms.wx.ctrl;

import java.util.List;

import javax.annotation.Resource;

import com.smart.wx.wxcms.entity.*;
import com.smart.wx.wxcms.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smart.common.BaseCtrl;
import com.smart.common.util.AjaxResult;

/**
 * 问卷微信端
 *
 * @author hermit
 * @version 2.0
 * @date 2018-07-11 20:58:43
 */
@Controller
@RequestMapping("/front/paperindex")
public class PaperIndexCtrl extends BaseCtrl {

    @Resource
    private PaperInfoService paperInfoService;

    @Resource
    private PaperQuestionService paperQuestionService;

    @Resource
    private PaperOptionService paperOptionService;


    /**
     * 获取问卷页面 [该url 配置到拦截器中]
     */
    @RequestMapping("/getPaperIndex/{account}/{paperInfoId}")
    public String getPaperIndex(@PathVariable String account,@PathVariable String paperInfoId) throws Exception {
        return "redirect:/views/front/paper/index.html?account=" + account + "&paperInfoId=" + paperInfoId;
    }






    /**
     * 获取问卷基本信息
     */
    @ResponseBody
    @RequestMapping("/getPaperInfo")
    public AjaxResult getPaperInfo(PaperQuestion paperQuestion) throws Exception {

        PaperInfo paperInfo = new PaperInfo();
        paperInfo.setId(paperQuestion.getPaperInfoId());
        paperInfo = this.paperInfoService.queryObject(paperInfo);

        return AjaxResult.success(paperInfo);
    }



    /**
     * 获取问卷列表(供用户填写问卷)
     */
    @ResponseBody
    @RequestMapping("/getPaperQuestionList")
    public AjaxResult getPaperQuestionList(PaperQuestion paperQuestion) throws Exception {

        List<PaperQuestion> paperQuestionList = paperQuestionService.queryList(paperQuestion);

        if(paperQuestionList != null && paperQuestionList.size() > 0){

            for(PaperQuestion bean : paperQuestionList){

                PaperOption paperOption = new PaperOption();
                paperOption.setPaperQuestionId(bean.getId());

                List<PaperOption> paperOptionList = this.paperOptionService.queryList(paperOption);
                bean.setOption(paperOptionList);
            }
        }

        return AjaxResult.success(paperQuestionList);
    }

//    /**
//     * 用户填写保存
//     */
//    @ResponseBody
//    @RequestMapping("/voteApplySave")
//    public AjaxResult voteApplySave(VoteApply voteApply) throws Exception {
//
//        String sessionid = request.getSession().getId();
//        String openId = WxMemoryCacheClient.getOpenid(sessionid);
//        voteApply.setOpenId(openId);
//
//        return this.voteApplyService.save(voteApply);
//    }

}
